//publishInformatiob.js
 const app = getApp();
 const apiUrl = app.data.url;
Page({
  data: {
    list:[],
    list2:[],
    byList:[],
    tab: 0 ,
    lat:"",
    long:"",

    },
    
  tab_slide: function (e) {//滑动切换tab   
    var that = this;
    that.setData({ tab: e.detail.current });
  },
  tab_click: function (e) {//点击tab切换  
    var that = this;
    if (that.data.tab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        tab: e.target.dataset.current
      })
    }
  },  
  toRelease: function () {
    wx.navigateTo({    //保留当前页面，跳转到应用内的某个页面（最多打开5个页面，之后按钮就没有响应的）
      url: "../../pages/release/releaseInfo"
    })
  },
  toUserCenter: function () {
    wx.redirectTo({
      url: "../../pages/userCenter/userCenter"
    })
  },
  //获取列表信息
  querypagelist:(type,lat,long,that) => {
    
    wx.request({
      url: apiUrl + 'api.php/info/querypagelist', //接口地址
      data: {
        "page": "",           //  页码，默认1
        "limit": "",          //  每页限制个数
        "type": type,          //  类型 默认 1 1：提供寄养服务 2：寻求帮养 
        "lat": lat,           //  纬度 默认是杭州的维度
        "lng": long,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: res =>{
        wx.hideLoading();
        const list = res.data.data.list;      
        if(type == 1){
          that.setData({
            list: list
          })
        }else{
          that.setData({
            list2: list
          })
        }      
      }
    })
  },
  onLoad: function () {
    const that = this;
    wx.getStorage({
      key: 'address',
      success: function (res) {
        const lat = res.data.lat;
        const long = res.data.long;
        that.setData({
          lat : lat,
          long: long
        })
         that.querypagelist(1,lat,long,that);
         that.querypagelist(2, lat, long, that);
      }
      
    });
     wx.showLoading({
      title: '加载中',
    });

    
  },
  //分享
  onShareAppMessage() {
    return {
      title: '留守猫',
      path: 'pages/square/publishedInfo'
    }
  },
})
